#use "test09_parser.ml";;

let rec post_string s i p = (
	let length = String.length s in
	if i >= length then (
		post (length + 1, length + 1) '\x1a' p
	) else (
		let p = post (i + 1, i + 2) s.[i] p in
		post_string s (i + 1) p
	)
);;

print_string "[1] ";;
flush stdout;;

let p = create ();;
let p = post_string "(-)" 0 p;;

flush stderr;;

if accepted p then (
	begin match result p with
	| Some (Sub (None, Some '-', None)) ->
		begin match errors p with
		| [(3, 3), Expected_expr; (2, 2), Expected_expr] ->
			print_string "OK.\n";
		| _ ->
			raise (Failure "BAD ERRORS DETECTED!!")
		end
	| _ ->
		raise (Failure "BAD RESULT!!")
	end
) else (
	raise (Failure "NOT ACCEPTED!!")
);;

print_string "[2] ";;
flush stdout;;

let p = create ();;
let p = post_string "+" 0 p;;

flush stderr;;

if accepted p then (
	begin match result p with
	| Some (Add (None, Some '+', None)) ->
		begin match errors p with
		| [(2, 2), Expected_expr; (1, 1), Expected_expr] ->
			print_string "OK.\n";
		| _ ->
			raise (Failure "BAD ERRORS DETECTED!!")
		end
	| _ ->
		raise (Failure "BAD RESULT!!")
	end
) else (
	raise (Failure "NOT ACCEPTED!!")
);;
